<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description"           content="传智健康">
    <meta name="keywords"              content="传智健康">
    <meta name="viewport"              content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" >
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统<small>菜单</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-permisson :to="{ path: '/' }">首页</el-breadcrumb-permisson>
            <el-breadcrumb-permisson                    >系统</el-breadcrumb-permisson>
            <el-breadcrumb-permisson                    >菜单</el-breadcrumb-permisson>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input style="width: 200px;"           class="filter-permisson"
                          placeholder="名称"               v-model="queryPageBean.queryString"
                          @keyup.enter.native="this.queryPageBean.currentPage=1;this.select();"></el-input>
                <el-button                                class="dalfBut" @click="this.queryPageBean.currentPage=1;select();">查询</el-button>
                <el-button type="primary"                 class="butT"    @click="initAndMakeDialogVisible"              >添加</el-button>
            </div>
            <el-table size="small" current-row-key="id"   :data="pageResult.rows" stripe highlight-current-row>
                <el-table-column   type="name"            label="名称"     align="center" ></el-table-column>
                <el-table-column   type="linkUrl"         label="访问路径"  align="center" ></el-table-column>
                <el-table-column   type="path"            label="路由路径"  align="center" ></el-table-column>
                <el-table-column   type="priority"        label="优先级"    align="center" ></el-table-column>
                <el-table-column   prop="description"     label="描述"     align="center"></el-table-column>
                <el-table-column   type="icon"            label="图标"     align="center" ></el-table-column>
                <el-table-column                          label="操作"     align="center">
                    <template      slot-scope="scope">
                        <el-button type="primary"         size="mini"      @click="initAndMakeDialogVisible(scope.row)">更新</el-button>
                        <el-button type="danger"          size="mini"      @click="delete(scope.row)"                  >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div        class="pagination-container">
                <el-pagination
                        class              ="pagination"
                        @current-change    ="select"
                        :current-page.sync ="queryPageBean.currentPage"
                        :page-size.sync    ="queryPageBean.pageSize"
                        layout             ="total, prev, pager, next, jumper"
                        :total             ="pageResult.total">
                </el-pagination>
            </div>
            <div        class="add-form">
                <el-dialog   :title="dialog_title"  :visible.sync="dialog.visible" >
                    <el-form label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-permisson label="名称">
                                    <el-input v-model="menu.name"/>
                                </el-form-permisson>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-permisson label="访问路径">
                                    <el-input v-model="menu.linkUrl"/>
                                </el-form-permisson>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-permisson label="路由路径">
                                    <el-input v-model="menu.path"/>
                                </el-form-permisson>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-permisson label="优先级">
                                    <el-input v-model="menu.priority"/>
                                </el-form-permisson>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-permisson label="描述">
                                    <el-input v-model="menu.description"/>
                                </el-form-permisson>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-permisson label="图标">
                                    <el-input v-model="menu.icon"/>
                                </el-form-permisson>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button                @click="dialog.visible = false"                  >取消</el-button>
                        <el-button type="primary" @click="add"     v-if="dialog.for_what=='add'"   >确定</el-button>
                        <el-button type="primary" @click="update"  v-if="dialog.for_what=='update'">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            queryPageBean: {
                queryString:         null,
                currentPage:             1,
                pageSize:            10,
            },
            pageResult:{
                total:               0,
                rows:                []
            },
            menu: {
                id:                  "",
                name:                "",
                linkUrl:             "",
                path:                "",
                priority:            "",
                description:         "",
                icon:                ""
            },
            dialog: {
                for_what:           "add",      //["add","update"]
                visible:            false,      //对话框是否可见
            },
        },
        computed: {
            dialog_title(){
                return this.dialog.for_what=="add"?"添加一个新的菜单":"更新一个菜单";
            }
        },
        created() {
            this.select();
        },
        methods: {
            add() {
                axios.post("/menu/add.do",this.menu).then((response)=>{
                    msg(response);
                    if(response.data.flag) this.dialog.visible = false;
                }).finally(()=>{
                    this.select();
                });
            },
            remove(row) {
                this.$confirm(  '此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText:  '确定',
                    cancelButtonText:   '取消',
                    type:               'warning',
                    center:             true
                }).then(() => {
                    axios.get("/menu/delete.do?id="+row.id).then((response)=>{
                        msg(response);
                        if(response.data.flag) return false;
                    });
                })
            },
            update() {
                axios.post("/menu/update.do",this.menu).then((response)=>{
                    msg(response);
                    if(response.data.flag) this.dialog.visible = false;
                }).finally(()=>{
                    this.select();
                });
            },
            select() {
                axios.post("/menu/selectPage.do",this.queryPageBean).then((response)=>{
                    this.pageResult= response.data;
                });
            },
            initAndMakeDialogVisible(row) {
                this.menu = {};
                this.dialog.for_what=(row?"add":"update");
                if(this.dialog.for_what="update"){
                    axios.get("/menu/selectById.do?id="+row.id).then((response)=>{
                        msg(response);
                        if(response.data.flag) return false;
                        this.menu = response.data.data;
                        this.dialog.visible=true;
                    });
                }
            }
        }
    });
    function msg(response){
        this.$message({type:response.data.flag?"success":"error",message:response.data.message});
    }
</script>
</html>